﻿using AutoMapper;
using MediatR;
using Traceability.App.Applications.Command.TraceabilityManagement;
using Traceability.Domain.Entity;
using Traceability.Domain.Repository;
using Traceability.Enum;

namespace Traceability.App.Applications.CommandHand.TraceabilityManagementmodel
{
    public class UpdataTraceabilityCommandHandler : IRequestHandler<UpdataTraceabilityCommand, ApiResult<int>>
    {
        private readonly IBaseRepository<TraceabilityManagement> _traceability;
        private readonly IMapper mapper;

        public UpdataTraceabilityCommandHandler(IBaseRepository<TraceabilityManagement> traceability, IMapper mapper)
        {
            _traceability = traceability;
            this.mapper = mapper;
        }

        public Task<ApiResult<int>> Handle(UpdataTraceabilityCommand request, CancellationToken cancellationToken)
        {
            var result = new ApiResult<int>();
            var tracea = mapper.Map<TraceabilityManagement>(request);

            tracea.createTime = request.CreateTime;
            tracea.createUserName = "张三";
            tracea.updateTime = DateTime.Now;
            tracea.updateUserName ="张三";
            tracea.Informationlmprovement = 0;
          
            tracea.del = 0;
            _traceability.Update(tracea);
            result.data = 1;
            result.Message = "修改成功";

            return Task.FromResult(result);
        }
    }
}
